package com.itasura.ehcache.repository;

import com.itasura.ehcache.entity.User;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author sailor wang
 * @date 2018/11/12 6:20 PM
 * @description
 */
public interface UserRepository extends JpaRepository<User, Long> {

    @Cacheable(cacheNames = "user", key = "#p0", condition = "#p0.length() < 10")
    User findByName(String name);


    @CacheEvict(cacheNames = "user")
    @Transactional
    int deleteByName(String name);
}